home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / applic / ncsa / Mac / Telnet2.6 / prerelease / d4 / Telnet2.6.1d4.src.sit.hqx / Telnet 2.6.1d4 source / source / tek / tekrgmac.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-18  |  12.4 KB  |  596 lines

  1. /*
  2. rgmac.c by Gaige B. Paulsen
  3.   spawned from rgp.c by Aaron Contorer for NCSA
  4. Copyright 1987, board of trustees, University of Illinois
  5.  
  6. Routines for Macintosh Window output.  
  7. */
  8.  
  9. #ifdef MPW
  10. #pragma segment TEKMAIN
  11. #endif
  12.  
  13. #include <stdio.h>
  14. #include <String.h>
  15. #include <Packages.h>
  16.  
  17. #include "tekrgmac.proto.h"
  18. #include "TelnetHeader.h"
  19. #include "maclook.proto.h"
  20. #include "vgtek.proto.h"
  21. #include "mydnr.proto.h"
  22. #include "rsmac.proto.h"
  23. #include "netevent.proto.h"
  24. #include "rg0.proto.h"
  25. #include "rgmp.proto.h"
  26. #include "InternalEvents.h"
  27. #include "tekdefs.h"        /* NCSA: sb - all the TEK defines are now here */
  28.  
  29. //#define TEK_DEBUG1
  30. #ifdef    TEK_DEBUG1
  31. #include "debug.h"
  32. #define    TEK_DEBUG_PRINT(x)    putln(x)
  33. char    TEK_DEBUG_STRING    [512];
  34. #else
  35. #define    TEK_DEBUG_PRINT(x)
  36. #endif
  37.  
  38. /*--------------------------------------------------------------------------*/
  39. /* Some variable definitions are needed before we give the code                */
  40. /*                                                                             */
  41. /*--------------------------------------------------------------------------*/
  42.  
  43. long    RGMlastclick;
  44. short    RGMcolor[]=
  45.     { 30,            /* black */
  46.       33,            /* white */
  47.       205,            /* red */
  48.       341,            /* green */
  49.       409,            /* blue */
  50.       273,            /* cyan */
  51.       137,            /* magenta */
  52.       69            /* yellow */
  53.       };
  54.  
  55. struct    RGMwindows *RGMwind[ MAXWIND ];
  56.  
  57. char    *RGMdevname(void)
  58. {
  59.     return("Macintosh Windows");
  60. }
  61.  
  62. short    RGMnewwin(void)
  63. {
  64.     short    i = 0;
  65.  
  66.     while ((i < MAXWIND) && (RGMwind[i] != nil)) i++;
  67.  
  68.     if (i >= MAXWIND) return(-1);
  69.  
  70.     RGMwind[i] = (struct RGMwindows *) NewPtrClear(sizeof(struct RGMwindows));
  71.     if (RGMwind[i] == nil) {
  72.         return -1;
  73.         }
  74.  
  75.     RGMwind[i]->id = 'RGMW';
  76.  
  77.     RGMwind[i]->wind = GetNewWindow(256, NULL, kInFront);
  78.     if (RGMwind[i]->wind == 0L) {
  79.         DisposePtr((Ptr)RGMwind[i]);
  80.         RGMwind[i] = nil;
  81.         return -1;
  82.         }
  83.  
  84.     ((WindowPeek)RGMwind[i]->wind)->windowKind = WIN_TEK;
  85.     
  86.     RGMwind[i]->vg = -1;                /* BYU */
  87.     RGMwind[i]->vs = -1;                /* BYU */
  88.     RGMwind[i]->xorigin = 0;
  89.     RGMwind[i]->yorigin = 0;
  90.     RGMwind[i]->xscale  = WINXMAX;    /* BYU LSC - need the "W" here */
  91.     RGMwind[i]->yscale  = WINYMAX;    /* BYU LSC - need the "W" here */
  92.     RGMwind[i]->width   = 400;        /* BYU LSC - was 256 (size of old window resource */
  93.     RGMwind[i]->height  = 300;        /* BYU LSC - was 342 (size of old window resource */
  94.     RGMwind[i]->ingin   = 0;        /* BYU LSC */
  95.  
  96.     ValidRect(&RGMwind[i]->wind->portRect);  
  97.  
  98.     return(i);
  99. }
  100.  
  101. void    RGMinit(void)
  102. {
  103.     short    i;
  104.     for (i = 0; i < MAXWIND; i++)
  105.         RGMwind[i] = nil;
  106. }
  107.  
  108. short    RGMgin(short w)
  109. {
  110.     if (RGsetwind(w)) return(-1);
  111.  
  112.     setgraphcurs();
  113.     RGMwind[w]->ingin=1;
  114. }
  115.  
  116. short    RGMpencolor(short w, short color)
  117. {
  118.     if (RGsetwind(w) ) return(-1);
  119.     ForeColor((long) RGMcolor[color] );
  120. #ifdef    TEK_DEBUG_1
  121.     sprintf(TEK_DEBUG_STRING, "TEK: Setting pen color to %d", color);
  122.     putln(TEK_DEBUG_STRING);
  123. #endif
  124.  
  125. }
  126.  
  127. short    RGMclrscr(short w)
  128. {    
  129.     if (RGsetwind(w) ) return(-1);
  130.     PaintRect(&RGMwind[w]->wind->portRect);
  131.     TEK_DEBUG_PRINT("TEK: Clearing screen");                    
  132. }    
  133.  
  134. short    RGMclose(short w)
  135. {
  136.     if (RGsetwind(w) ) return(-1);
  137.  
  138.     DisposeWindow(RGMwind[w]->wind);
  139.     DisposePtr((Ptr)RGMwind[w]->name);
  140.     DisposePtr((Ptr)RGMwind[w]);
  141.     RGMwind[w] = nil;
  142. }
  143.  
  144. short    RGMpoint(short w, short x, short y)
  145. {
  146.     if (RGsetwind(w) ) return(-1);
  147.  
  148.     MoveTo(x,y);
  149.     LineTo(x,y);
  150.  
  151. short    RGMdrawline(short w, short x0, short y0, short x1, short y1)
  152. {
  153.     long    xl0, yl0, xl1, yl1;
  154.     
  155.     if (RGsetwind(w) )
  156.         return(-1);
  157.  
  158.     xl0 = ((long)x0 * RGMwind[w]->width) / INXMAX;
  159.     yl0 = (long)RGMwind[w]->height - (((long)y0 * RGMwind[w]->height) / INYMAX);
  160.     xl1 = ((long)x1 * RGMwind[w]->width) / INXMAX;
  161.     yl1 = (long)RGMwind[w]->height - (((long)y1 * RGMwind[w]->height) / INYMAX);
  162.  
  163.     MoveTo((short)xl0, (short)yl0);
  164.     LineTo((short)xl1, (short)yl1);
  165. }
  166.  
  167. void    RGMinfo(short w, short v, short a, short b, short c, short d)
  168. {
  169.     UNUSED_ARG(a)
  170.     UNUSED_ARG(b)
  171.     UNUSED_ARG(c)
  172.     UNUSED_ARG(d)
  173.     RGMwind[w]->vg=v;
  174. }
  175.  
  176. void    RGMpagedone(short w)
  177. {
  178.     UNUSED_ARG(w)
  179. }
  180.  
  181. void    RGMdataline(short w, short data, short count)
  182. {
  183.     UNUSED_ARG(w)
  184.     UNUSED_ARG(data)
  185.     UNUSED_ARG(count)
  186. }
  187.  
  188.  
  189. void    RGMcharmode(short w, short rotation, short size)
  190. {
  191.     UNUSED_ARG(w)
  192.     UNUSED_ARG(rotation)
  193.     UNUSED_ARG(size)
  194. }
  195.  
  196. void    RGMgmode(void)
  197. {}
  198.  
  199. void    RGMtmode(void)
  200. {}
  201.  
  202. void    RGMshowcur(void)
  203. {
  204. }
  205.  
  206. void    RGMlockcur(void)
  207. {
  208. }
  209.  
  210. void    RGMhidecur(void)
  211. {
  212. }
  213.  
  214. void    RGMbell(short w)
  215. {
  216.     UNUSED_ARG(w)
  217. }
  218.  
  219. void    RGMuncover(short w)
  220. {
  221.     UNUSED_ARG(w)
  222. }
  223.  
  224. short    RGMoutfunc(short (*f )())
  225. {
  226.     UNUSED_ARG(f)
  227.     return(0);    // Unused
  228. }
  229.  
  230. short    RGsetwind(short dnum)
  231. {
  232.     if (dnum<0 || dnum>=MAXWIND) return(-1);
  233.  
  234.     if (RGMwind[dnum] == nil) return -1;
  235.  
  236.     SetPort( RGMwind[dnum]->wind);
  237.     return(0);
  238. }
  239.  
  240. short    RGfindbyVG(short vg)
  241. {
  242.     short    i = 0;
  243.     
  244.     while (i < MAXWIND) {
  245.         if (RGMwind[i] != nil) {
  246.             if (RGMwind[i]->vg == vg)
  247.                 break;
  248.             }
  249.         i++;
  250.         }
  251.  
  252.     if (i >= MAXWIND) return(-1);
  253.     return(i);
  254. }
  255.  
  256. short    RGattach(short vg, short virt, char *name, short TEKtype)
  257. {
  258.     short            dnum;
  259.     unsigned long    time;
  260.     char            myname[256],ts[256];
  261.  
  262.     if ((dnum = RGfindbyVG(vg)) < 0) return(-1);
  263.  
  264.     RGMwind[dnum]->vs = virt;
  265.     RGMwind[dnum]->name = (unsigned char *) NewPtrClear((long) 256);        /* BYU LSC */
  266.  
  267.     if (RGMwind[dnum]->name == 0L) return(-2);
  268.  
  269.     myname[0] = 'Ñ';
  270.     if (TEKtype)
  271.         strcpy(&myname[1], "[4105] ");
  272.     else
  273.         strcpy(&myname[1], "[4014] ");
  274.         
  275.     strncpy(&myname[strlen(myname)],name,120);
  276.  
  277.     GetDateTime(&time);
  278.     IUTimeString(time,FALSE,(StringPtr) ts);        /* BYU LSC - Put time in the temp string */
  279.     p2cstr((StringPtr)ts);                                            /* BYU LSC */
  280.  
  281.     strncat(myname,"  ",2);                /* BYU - was 4 - Space, please */
  282.     strncat(myname,ts,64);                /* BYU - Place the time string at the end */
  283.     strcpy((char *) RGMwind[dnum]->name,myname);    /* BYU LSC */
  284.  
  285.     if (RGMwind[dnum]->wind != (GrafPtr) 0) {    /* BYU LSC */
  286.         c2pstr(myname);                            /* BYU LSC */
  287.         SetWTitle(RGMwind[dnum]->wind,(StringPtr)myname);    /* BYU LSC */
  288.     }
  289.  
  290.     return(0);
  291. }
  292.  
  293.  
  294. short    RGdetach( short vg)
  295. {
  296.         short    dnum;            /* BYU */
  297.         char    myname[256];            /* BYU LSC */
  298.  
  299.     if ((dnum = RGfindbyVG(vg)) < 0) return(-1);        /* BYU */
  300.     if (dnum >= MAXWIND)  return(-1);                    /* BYU */
  301.  
  302.     if (RGMwind[dnum]->vs != -1) {                                     /* BYU */
  303.         if (RGMwind[dnum]->wind != (GrafPtr) 0) {                    /* BYU */
  304. #if 1
  305.             strncpy((char *) RGMwind[dnum]->name,                /* BYU LSC */
  306.                     (char *) &RGMwind[dnum]->name[1],255);        /* BYU LSC */
  307.             strncpy(myname, (char *) RGMwind[dnum]->name,256);    /* BYU LSC */
  308.             c2pstr(myname);                                        /* BYU LSC */
  309.             SetWTitle(RGMwind[dnum]->wind,(StringPtr)myname);                /* BYU LSC */
  310. #else
  311.             strncpy((char *) RGMwind[dnum]->name,                /* BYU LSC */
  312.                     (char *) &RGMwind[dnum]->name[1],255);        /* BYU LSC */
  313.             SetWTitle(RGMwind[dnum]->wind,RGMwind[dnum]->name);    /* BYU LSC */
  314. #endif
  315.         }                            /* BYU */
  316.     }                                /* BYU */
  317.     return(0);                        /* BYU */
  318. }
  319.  
  320. short    RGfindbywind( GrafPtr wind)
  321. {
  322.     short    i = 0;
  323.  
  324.     while (i < MAXWIND) {
  325.         if (RGMwind[i] != nil) {
  326.             if (RGMwind[i]->wind == wind)
  327.                 break;
  328.             }
  329.         i++;
  330.         }
  331.  
  332.     if (i >= MAXWIND) return(-1);
  333.     return(i);
  334. }
  335.  
  336. short    RGupdate( GrafPtr wind)
  337. {
  338.     short    i = 0,
  339.             done;
  340.  
  341.     if ((i = RGfindbywind(wind)) < 0)
  342.         return(-1);
  343.  
  344.     SetPort(wind);
  345.     BeginUpdate(wind);
  346.  
  347.     VGstopred(RGMwind[i]->vg);
  348.     VGpage(RGMwind[i]->vg);
  349.     done = VGpred(RGMwind[i]->vg,RGMwind[i]->vg);
  350.  
  351.     EndUpdate(wind);
  352.     if (!done)
  353.         netputevent(USERCLASS,RG_REDRAW,RGMwind[i]->vg,0);
  354.     return(done);
  355. }
  356.  
  357. short    RGsupdate( short i)
  358. {
  359.     short    rg;
  360.  
  361.     rg = RGfindbyVG(i);
  362.  
  363.     if (rg < 0) return(0);
  364.     SetPort(RGMwind[rg]->wind);
  365.     if (!VGpred(RGMwind[rg]->vg,RGMwind[rg]->vg))
  366.     {
  367.         netputevent(USERCLASS,RG_REDRAW,i,0);
  368.     }
  369.     else
  370.         return(1);
  371.     return(0);
  372. }
  373.  
  374. short    RGgetVG(GrafPtr wind)
  375. {
  376.     short    i;
  377.  
  378.     i = RGfindbywind(wind);
  379.  
  380.     return(RGMwind[i]->vg);
  381. }
  382.  
  383. short    RGgetdnum(GrafPtr wind)
  384. {
  385.     return(RGfindbywind(wind));
  386. }
  387.  
  388. short    RGgetVS(short dnum)
  389. {
  390.     return(RGMwind[dnum]->vs);
  391. }
  392.  
  393. short    inSplash(Point *p1, Point *p2)
  394. {
  395.     if ((p1->h - p2->h > 3) || (p2->h - p1->h > 3))
  396.         return(0);
  397.     if ((p1->v - p2->v > 3) || (p2->v - p1->v > 3))
  398.         return(0);
  399.  
  400.     return(1);
  401. }
  402.  
  403. void VidSync( void)
  404. {
  405.     long    a;
  406.     a = TickCount();            /* BYU LSC */
  407.     while (a == TickCount())
  408.         /* loop*/;    /* BYU LSC */
  409. }
  410.  
  411. void RGmousedown
  412.   (
  413.     GrafPtr wind,
  414.     Point *wherein
  415.   )
  416. {
  417.     unsigned long    lx,ly;        /* NCSA: SB */
  418.     char            thispaceforent[6];
  419.     short            i;
  420.     Point            where;
  421.     char            dum[32];
  422.  
  423.     where = *wherein;
  424.     if ((i = RGfindbywind(wind)) < 0)
  425.         return;
  426.  
  427.     if (!RGMwind[i]->ingin)
  428.     {
  429.     Point    anchor,current,last;
  430. #if 0                            /* BYU LSC - was "#ifndef MPW" */
  431.     long    TickCount();
  432. #endif MPW
  433.     long    tc;
  434.     short    x0,y0,x1,y1;
  435.     Rect    rect;
  436.     
  437.         SetPort(wind);
  438.     
  439.         last  = where;
  440.         current = where;
  441.         anchor = where;
  442.     
  443.         PenPat(PATTERN(qd.gray));    
  444.         PenMode(patXor);
  445.     
  446.         SetRect(&rect,0,0,0,0);
  447.     
  448.         while (StillDown())
  449.         {
  450.             GetMouse(¤t);
  451.             if (inSplash(¤t,&anchor)) continue;
  452.             tc = TickCount();
  453.             while(TickCount() == tc)
  454.                 /* loop */;
  455.             VidSync();
  456.             FrameRect(&rect);
  457.     
  458.             if (anchor.v < current.v)
  459.             {
  460.                 rect.top = anchor.v;
  461.                 rect.bottom = current.v;
  462.             }
  463.             else
  464.             {
  465.                 rect.top = current.v;
  466.                 rect.bottom = anchor.v;
  467.             }
  468.     
  469.             if (anchor.h < current.h)
  470.             {
  471.                 rect.left = anchor.h;
  472.                 rect.right = current.h;
  473.             }
  474.             else
  475.             {
  476.                 rect.right = anchor.h;
  477.                 rect.left = current.h;
  478.             }
  479.     
  480.             FrameRect(&rect);
  481.             last = current;
  482.         }
  483.     
  484.         FrameRect(&rect);
  485.  
  486.         PenPat(PATTERN(qd.black));    
  487.         PenMode(patCopy);
  488.  
  489.         if (!inSplash(&anchor,¤t))
  490.         {
  491.             x0 = (short) ((long) rect.left * RGMwind[i]->xscale / RGMwind[i]->width );
  492.             y0 = (short) (RGMwind[i]->yscale -
  493.                     (long) rect.top * RGMwind[i]->yscale / RGMwind[i]->height);
  494.             x1 = (short) ((long) rect.right * RGMwind[i]->xscale / RGMwind[i]->width);
  495.             y1 = (short) (RGMwind[i]->yscale -
  496.                     (long) rect.bottom * RGMwind[i]->yscale / RGMwind[i]->height);
  497.             x1 = (x1 < x0+2) ? x0 + 4 : x1;
  498.             y0 = (y0 < y1+2) ? y1 + 4 : y0;
  499.  
  500.             VGzoom( i,
  501.                     x0 + RGMwind[i]->xorigin,
  502.                     y1 + RGMwind[i]->yorigin,
  503.                     x1 + RGMwind[i]->xorigin,
  504.                     y0 + RGMwind[i]->yorigin);
  505.  
  506.             VGpage(RGMwind[i]->vg);
  507.  
  508.             RGMwind[i]->xscale  = x1 - x0;
  509.             RGMwind[i]->yscale  = y0 - y1;
  510.             RGMwind[i]->xorigin = x0 + RGMwind[i]->xorigin;
  511.             RGMwind[i]->yorigin = y1 + RGMwind[i]->yorigin;
  512.  
  513.             while(!VGpred(RGMwind[i]->vg,RGMwind[i]->vg))
  514.                 Stask();
  515.             RGMlastclick = 0L;
  516.         }
  517.         else
  518.         {
  519.             if (RGMlastclick && ((RGMlastclick + GetDblTime()) > TickCount()))
  520.             {
  521.                 RGMwind[i]->xscale  = WINXMAX;    /* BYU LSC - need the "W" here */
  522.                 RGMwind[i]->yscale  = WINYMAX;    /* BYU LSC - need the "W" here */
  523.                 RGMwind[i]->xorigin = 0;
  524.                 RGMwind[i]->yorigin = 0;
  525.  
  526.                 VGzoom(i,0,0,WINXMAX-1,WINYMAX-1);    /* BYU LSC - need the "W" here */
  527.                 VGpage( RGMwind[i]->vg);
  528.                 while(!VGpred(RGMwind[i]->vg,RGMwind[i]->vg))
  529.                     Stask();
  530.                 RGMlastclick = 0L;
  531.             }
  532.             else RGMlastclick = TickCount();
  533.         }
  534.         return;
  535.     
  536.     }
  537.     
  538.     /* NCSA: SB */
  539.     /* NCSA: SB - These computations are being truncated and turned into signed ints. */
  540.     /* NCSA: SB - Just make sure everything is cast correctly, and were fine */
  541.     
  542.     lx = ((unsigned long)RGMwind[i]->xscale * (unsigned long)where.h)     /* NCSA: SB */
  543.             / (unsigned long)RGMwind[i]->width;                             /* NCSA: SB */
  544.     ly = (unsigned long)RGMwind[i]->yscale -                             /* NCSA: SB */
  545.         ((unsigned long)RGMwind[i]->yscale * (unsigned long)where.v) / (unsigned long)RGMwind[i]->height; /* NCSA: SB */
  546.  
  547.     VGgindata(RGMwind[i]->vg,(unsigned short) lx,(unsigned short)ly,' ',thispaceforent);    /* NCSA: SB */
  548.  
  549. #if 0                                                    /* BYU LSC - not needed */
  550. sprintf(dum,"GIN i: %d, vs: %d\015",i,RGMwind[i]->vs);    /* BYU 2.4.18 - changed \n to \015 */
  551. putln(dum);
  552. #endif                                                    /* BYU LSC - not needed */
  553.  
  554.     RSsendstring(RGMwind[i]->vs,thispaceforent,5);
  555.     sprintf(dum," \r\n");
  556.     RSsendstring(RGMwind[i]->vs,dum,3);
  557.     
  558.  
  559.     /*    RGMwind[i]->ingin = 0; */
  560.     unsetgraphcurs();
  561.     RGMlastclick = TickCount();
  562. }
  563.  
  564.  
  565. /*--------------------------------------------------------------------------*/
  566. /* NCSA: SB - RGMgrowme                                                        */
  567. /* This allows the TEK window to be grown like any other real window.        */
  568. /* The grow box is not shown on the screen, but it acts accordingly     - SMB    */
  569. /*--------------------------------------------------------------------------*/
  570. void    RGMgrowme(short myRGMnum,GrafPtr window, long *where, short modifiers)
  571. {
  572.     UNUSED_ARG(modifiers)
  573.     long size;
  574.     Rect SizRect;
  575.  
  576.     SetRect(&SizRect, 50, 50, 1500, 1500);            /* NCSA: SB - max size - arbitrary */
  577.  
  578.     if (where)
  579.     {        
  580.         size = GrowWindow(window, *(Point *) where, &SizRect);    
  581.         if (size != 0L)
  582.             {
  583.             SizeWindow(window, size & 0xffff, (size >> 16) & 0xffff, FALSE);
  584.             RGMwind[myRGMnum]->width   = window->portRect.right - window->portRect.left;        
  585.             RGMwind[myRGMnum]->height  = window->portRect.bottom - window->portRect.top;         
  586.             VGpage(RGMwind[myRGMnum]->vg);
  587.             InvalRect(&window->portRect);
  588.             RGupdate(window);
  589.             }
  590.         else
  591.             return;                            /* user skipped growing */
  592.     }
  593. }
  594.  
  595.